import { customForm } from "@/components/ProForm/interface/index";
import { Login, User } from "@/api/interface";
import { ProTableValue } from "@/interface/public";

export function useChangePwdForm(proTableBox: ProTableValue) {
  let changePwdForm = reactive<customForm<User.ResUserList>>({
    form: {},
    title: "用户",
    visible: false,
    formCols: 1,
    options: [
      {
        label: "id",
        prop: "id",
        hide: true,
        type: "input"
      },
      {
        type: "input",
        label: "username",
        hide: false,
        prop: "username",
        defaultValue: "",
        rules: [{ required: true, message: "username", trigger: "blur" }],
        attrs: {
          disabled: true
        }
      },
      {
        type: "input",
        label: "password",
        hide: false,
        defaultValue: "",
        prop: "password",
        rules: [{ required: true, message: "password", trigger: "blur" }]
      }
    ]
  });

  const savePwdForm = async (form: Login.ReqLoginForm) => {
    await userUpPasswordByAdmin(form);
    changePwdForm.visible = false;
    proTableBox.value?.getTableList();
  };
  return {
    changePwdForm,
    savePwdForm
  };
}
